import { useReducer } from 'react';

/**
 * 定义初始状态信息
 */
export interface IstateType {}

/**
 * 新增和编辑页面操作枚举
 * @CLEAR_RECEIVE  清空存入 数据
 *
 */
export enum IAcquisitionActionEnum {
  CLEAR_RECEIVE = 'clearAllReceive',
}

/**
 * 定义新增和编辑页面操作匹配
 * @type 操作类型
 * @payload 传递数据
 */
export interface IActionType {
  type: IAcquisitionActionEnum;
  payload?: any;
}

export const useAcquisitionManageReducer = () => {
  /** 初始化状态 */
  const initState: IstateType = {};

  const acquisitionManageReducer = (state: IstateType, action: IActionType) => {
    switch (action?.type) {
      /**
       *  清空已选数据
       */
      case IAcquisitionActionEnum.CLEAR_RECEIVE:
        return {
          ...state,
          leftSelectRows: [],
          leftSelectKeys: [],
          leftExpandedKeys: [],
          leftAutoExpandParent: false,
          leftSelectName: [],
        };

      default:
        return {
          ...state,
          ...initState,
        };
    }
  };

  const [state, acquisitionDispatch] = useReducer(acquisitionManageReducer, initState);

  return {
    ...state,
    acquisitionDispatch,
  };
};
